<?php
class Comment extends AppModel {
	public $name = 'Comment';
	public 	$useTable  = 'comments';
	/* public $belongsTo = array(
		'User' => array(
			'className' => 'User',
			'foreignKey' => 'user_id'
		),
		'Article' => array(
			'className' => 'Article',
			'foreignKey' => 'article_id'
        )
	); */
	
	function getCommentById($id){
		return $this->find('first', array(
			'conditions' => array(
				'id'=> $id
			)
		));
	}
	
	function getListCommentsByArticleId($id){
		return $this->find('all', array(
			'conditions' => array(
				'article_id'=> $id
			)
		));
	}
	function countCommentsByArticleId($id){
		return $this->find('count', array(
			'conditions' => array(
				'article_id'=> $id
			)
		));
	}
	public function addComment($user_id = 0, $article_id=0, $title = '', $content = ''){
		if(!empty($user_id) && !empty($article_id) && !empty($content)){
			$data['Comment']['user_id'] = $user_id;
			$data['Comment']['article_id'] = $article_id;
			$data['Comment']['title'] = $title;
			$data['Comment']['content'] = $content;
			//save data
			return $this->save($data);
		}else{
			return false;
		}
	}
}